ext/pgsql: escape table name, delimiter, null marker in pg_copy_from/to#56
Closed
ext/pgsql: escape table name, delimiter, null marker in pg_copy_from/to#56
Conversation
The COPY query embedded the table_name argument with a raw "%s" and the delimiter and null marker inside literal E'..' wrappers, so caller-supplied strings could break out and run side queries. Route bare table names through build_tablename (the same helper pg_insert/update/select/delete have used since bug #62978), and pass the delimiter and null marker through PQescapeLiteral. pg_copy_to keeps the parenthesised (query) source form documented in bug 73498, but wraps it in an extra paren pair so a string like (SELECT 1); DROP TABLE x; -- becomes a syntax error inside the outer parens instead of escaping out into a second statement. Closes phpGH-21985
0b0a808 to
bc6f630
Compare
Owner
Author
|
Verified on php#21985. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Staging PR for php#21985 v2. Picks up devnexen review feedback on the original PR.
null_as was embedded raw inside E'%s', so a caller string could close the literal and run side DDL. Routed through PQescapeLiteral, same for the delimiter.
pg_copy_to had the same identifier hole pre-PR. Bare table names go through build_tablename; the parenthesised (query) form documented in bug 73498 still passes through unchanged.
Tests cover the null_as injection and the pg_copy_to table-name injection. 06_bug73498.phpt confirms the (query) BC is intact.